package com.sample.kokou;

import java.util.ArrayList;
import android.util.Pair;

public class DatabaseInfo {
    public static final String name = "test.db";
    public static final String persons = "persons";
    public static final ArrayList<Pair<String, String>> schema =
        new ArrayList<Pair<String, String>>() {
        private static final long serialVersionUID = -3686377904429751929L;
        {
            add(new Pair<String, String>("name", "VARCHAR"));
            add(new Pair<String, String>("age", "INTEGER"));
        }
    };
    public static final ArrayList<Pair<String, Integer>> values =
        new ArrayList<Pair<String, Integer>>() {
        private static final long serialVersionUID = 8029577387080679524L;
        {
            add(new Pair<String, Integer>("山田 浩一郎", 25));
            add(new Pair<String, Integer>("佐久間 慎吾", 37));
            add(new Pair<String, Integer>("天城 京子", 18));
        }
    };

    public static String createTable() {
        String create_statement = "CREATE TABLE " + persons + " (" +
            "id INTEGER PRIMARY KEY AUTOINCREMENT, ";
        for(Pair<String, String> column : schema) {
            create_statement += column.first + " " + column.second + ", ";
        }
        return create_statement.replaceAll(", $", ");");
    }

    public static ArrayList<String> insertStatements() {
        ArrayList<String> insert_statements = new ArrayList<String>();
        String insert_statement = "INSERT INTO " + persons + " (";
        for(Pair<String, String> column : schema) {
            insert_statement += column.first + ", ";
        }
        insert_statement = insert_statement.replaceAll(", $", ") VALUES (");
        for(Pair<String, Integer> value : values) {
            insert_statements.add(insert_statement + "'" + value.first + "', " + value.second + ");");
        }
        return insert_statements;
    }

    public static String selectAll() {
        String select_statement = "SELECT ";
        for(Pair<String, String> column : schema) {
            select_statement += column.first + ", ";
        }
        return select_statement.replaceAll(", $", " FROM ") + persons + ";";
    }

    public static String[] columns() {
        ArrayList<String> columns = new ArrayList<String>();
        for(Pair<String, String> column : schema) {
            columns.add(column.first);
        }
        return columns.toArray(new String[0]);
    }
}